﻿using UnityEngine;
using System.Collections;
/// <summary>
/// 此脚本添加在门/门把上，用于玩家交互
/// </summary>
public class ControlDoor : MonoBehaviour {
	[SerializeField] bool canOpen = true;
	[SerializeField] float minDis = 2f;
	float minDis_2;
	GameObject target;
	DoorControler doorCtrl;
	// Use this for initialization
	void Start () {
		target = StaticVarFunc.rightHand;
		minDis_2 = minDis * minDis;
		doorCtrl = GetComponentInParent<DoorControler> ();
	}
	
	// Update is called once per frame
	void Update () {
		if (!canOpen) {
			return;
		}
		if (MyInput.GetInputOfType(InputType.OPEN_DOOR) && (target.transform.position - transform.position).sqrMagnitude <= minDis_2) {
			doorCtrl.changeDoorStatus ();
		}
	}
}
